package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysGoodsEarn;
import com.ruoyi.system.service.ISysGoodsEarnService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品库存Controller
 *
 * @author ruoyi
 * @date 2022-10-30
 */
@RestController
@RequestMapping("/system/earn")
public class SysGoodsEarnController extends BaseController
{
    @Autowired
    private ISysGoodsEarnService sysGoodsEarnService;

    /**
     * 查询商品库存列表
     */
    @PreAuthorize("@ss.hasPermi('system:earn:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysGoodsEarn sysGoodsEarn)
    {
        startPage();
        List<SysGoodsEarn> list = sysGoodsEarnService.selectSysGoodsEarnList(sysGoodsEarn);
        return getDataTable(list);
    }

    /**
     * 导出商品库存列表
     */
    @PreAuthorize("@ss.hasPermi('system:earn:export')")
    @Log(title = "商品库存", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysGoodsEarn sysGoodsEarn)
    {
        List<SysGoodsEarn> list = sysGoodsEarnService.selectSysGoodsEarnList(sysGoodsEarn);
        ExcelUtil<SysGoodsEarn> util = new ExcelUtil<SysGoodsEarn>(SysGoodsEarn.class);
        util.exportExcel(response, list, "商品库存数据");
    }

    /**
     * 获取商品库存详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:earn:query')")
    @GetMapping(value = "/{outGoodsId}")
    public AjaxResult getInfo(@PathVariable("outGoodsId") Long outGoodsId)
    {
        return AjaxResult.success(sysGoodsEarnService.selectSysGoodsEarnByOutGoodsId(outGoodsId));
    }

    /**
     * 新增商品库存
     */
    @PreAuthorize("@ss.hasPermi('system:earn:add')")
    @Log(title = "商品库存", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysGoodsEarn sysGoodsEarn)
    {
        return toAjax(sysGoodsEarnService.insertSysGoodsEarn(sysGoodsEarn));
    }

    /**
     * 修改商品库存
     */
    @PreAuthorize("@ss.hasPermi('system:earn:edit')")
    @Log(title = "商品库存", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysGoodsEarn sysGoodsEarn)
    {
        return toAjax(sysGoodsEarnService.updateSysGoodsEarn(sysGoodsEarn));
    }

    /**
     * 删除商品库存
     */
    @PreAuthorize("@ss.hasPermi('system:earn:remove')")
    @Log(title = "商品库存", businessType = BusinessType.DELETE)
    @DeleteMapping("/{outGoodsIds}")
    public AjaxResult remove(@PathVariable Long[] outGoodsIds)
    {
        return toAjax(sysGoodsEarnService.deleteSysGoodsEarnByOutGoodsIds(outGoodsIds));
    }
}
